package com.zcmyth;

import java.lang.StringBuilder;

public class PrimitiveTypes {
  public static void main(String[] args) {
    /*
     * System.out.println(Byte.SIZE ); System.out.println(Short.SIZE );
     * System.out.println(Integer.SIZE ); System.out.println(Long.SIZE );
     * 
     * //System.out.println(Boolean.SIZE ); System.out.println(Character.SIZE );
     * System.out.println(Float.SIZE ); System.out.println(Double.SIZE );
     */
    System.out.println(toOctal("10001", 16));
    System.out.println(toAny(10, 8));

  }

  boolean isPalindrome(int x) {
    for (int i = 0; i < Integer.SIZE; i++) {

    }
    return false;
  }

  static void temp() {
    int r = 0;
    for (int i = 1; i < 1000; i++)
      if (i % 3 == 0 || i % 5 == 0)
        r += i;
    System.out.println(r);
  }

  static int toOctal(String value, int n) {
    int x = 1;
    int result = 0;
    for (int i = value.length() - 1; i >= 0; i--) {
      char c = value.charAt(i);
      int temp = c - '0';
      if (temp < 0 || temp >= n) {
        System.out.println("bug");
        return -1;
      } else {
        result += temp * x;
        x *= n;
      }
    }
    return result;
  }

  static String toAny(int value, int n) {
    StringBuilder sb = new StringBuilder();
    if (value == 0)
      return "0";
    while (value != 0) {
      int temp = value % n;
      sb.append((char) ('0' + temp));
      value = value / n;
    }
    return sb.reverse().toString();
  }

  /*
   * All programmers should be able to count in hexadecimal, and should be able
   * to convert between the binary, octal, and hex representations of a number.
   */

}